
    // Saves options to localStorage.
    function save_options() {
      var select = document.getElementById("alert_level");
      var level = select.children[select.selectedIndex].value;
      localStorage["alert_level"] = level;
      
      select = document.getElementById("check_search");
      var check = select.children[select.selectedIndex].value;
      localStorage["check_search"] = check;

      // Update status to let user know options were saved.
      var status = document.getElementById("status");
      status.innerHTML = "Options Saved.";
      setTimeout(function() {
        status.innerHTML = "";
      }, 750);
    }

    // Restores select box state to saved value from localStorage.
    function restore_options() {

      var optionsTitle = chrome.i18n.getMessage("optionsTitle");
      var titleH1 = document.getElementById("optionsTitle");
      titleH1.innerHTML = optionsTitle;
      
      var optionsAll = chrome.i18n.getMessage("optionsAll");
      var allOption = document.getElementById("opt_all");
      allOption.innerHTML = optionsAll;

      var optionsStock = chrome.i18n.getMessage("optionsStock");
      var stockOption = document.getElementById("opt_stock");
      stockOption.innerHTML = optionsStock;

      var optionsAvailable = chrome.i18n.getMessage("optionsAvailable");
      var availableOption = document.getElementById("opt_available");
      availableOption.innerHTML = optionsAvailable;

      var level = localStorage["alert_level"];
      if (!level) {
        return;
      }
      var select = document.getElementById("alert_level");
      for (var i = 0; i < select.children.length; i++) {
        var child = select.children[i];
        if (child.value == level) {
          child.selected = "true";
          break;
        }
      }
      
      var check = localStorage["check_search"];
      if (!check){return;}
      
      var selectCheck = document.getElementById("check_search");
      for (var i = 0; i < selectCheck.children.length; i++) {
        var child = selectCheck.children[i];
        if (child.value == check) {
          child.selected = "true";
          break;
        }
      }
    }

window.addEventListener("load", function()
{
  restore_options();
  document.getElementById("button")
          .addEventListener("click", save_options, false);
}, false);

